<?php
/**
 * common repository file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/08/20
 * Time: 06:07
 */
 
 namespace HiCommon\Repository;

class EntrustPermissionRoleRepository extends BaseRepository
{

    public function base_model(){
        return new \HiCommon\Model\EntrustPermissionRole();
    }

    /**
     * 根据用户id获取用户的所有权限
     *
     * @param $n_uid
     * @param $s_model
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function get_all_by_uid($n_uid,$s_model){
        return self::base_model()
                   ->where(
                     function($query)
                     use($n_uid,$s_model) {
                         $query->whereHas('role.role_user',
                           function ($query)
                           use($n_uid,$s_model){
                               $query->where('user_id', $n_uid)->where('model', $s_model);
                           });
                     }
                   )
                   ->get();
    }

    /**
     * 根据管理后台用户id获取管理后台用户的所有权限
     *
     * @param $n_uid
     * @param $s_model
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function get_admin_all_by_uid($n_uid){
        $s_model = 'admin';
        return self::get_all_by_uid($n_uid,$s_model);
    }

    /**
     * 根据商户后台用户id获取商户后台用户的所有权限
     *
     * @param $n_uid
     * @param $s_model
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function get_shop_all_by_uid($n_uid){
        $s_model = 'shop';
        return self::get_all_by_uid($n_uid,$s_model);
    }



}